﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Project
{
    class Payrolls
    {
        private static string query;

        /*
         * The following function shows all of the payrolls
         * that are in the database
         */
        public static DataTable showAllPayrolls()
        {
            DataTable dt = new DataTable();
            query = "SELECT * FROM tbl_PayBills";
            try
            {
                dt = AdoHelper.ExecuteDataTable(query);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
            return dt;
        }

        /*
         * The following function shows all of the with payrolls
         * of one employee with the given id.
         */
        public static DataTable searchPayroll(string id)
        {
            DataTable dt = new DataTable();
            query = "SELECT * FROM tbl_PayBills WHERE fld_employeeID Like '" + id + "'";
            try
            {
                dt = AdoHelper.ExecuteDataTable(query);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
            return dt;
        }

        /*
         * The following function adds a new payroll to the database. 
         */
        public static void addPayroll(string id, int salary, string date, string description)
        {
            query = "INSERT INTO tbl_PayBills(fld_employeeID, fld_salary, fld_date, fld_description)  VALUES('" + id + "', '" + salary + "', '" + date + "', '" + description + "')";
            AdoHelper.ExecuteNonQuery(query);
        }

        /*
         * The following function gets an update query that
         * contains the fields that the user would like to update
         * and updates them in the database.
         */
        public static void updatePayroll(string updateQuery)
        {
            AdoHelper.ExecuteNonQuery(updateQuery);
        }
    }
}
